//
//  ExercisePickerView.m
//  Water
//
//  Created by yh on 2018/1/16.
//  Copyright © 2018年 chenguibang. All rights reserved.
//

#import "ExercisePickerView.h"
#import <ScottAlertController/ScottAlertController.h>
@implementation ExercisePickerView


- (void)pickWithData:(NSArray *)data titleBlock:(ExercisePickerViewTitleBlock)titleBlock resultBlock:(ExercisePickerViewResultBlock)resultBlock at:(UIViewController *)controller{
    self.exercisePickerViewTitleBlock = titleBlock;
    self.exercisePickerViewResultBlock = resultBlock;
    self.datas = data;
    self.picker.delegate = self;
    self.picker.dataSource = self;
    [self.picker reloadAllComponents];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 200);
    self.backgroundColor = [APPManager shared].theme.viewControllerBackgroundColor;
    ScottAlertViewController *alertController = [ScottAlertViewController alertControllerWithAlertView:self preferredStyle:ScottAlertControllerStyleActionSheet];
    alertController.tapBackgroundDismissEnable = YES;
    [controller presentViewController:alertController animated:YES completion:nil];
}


// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return self.datas.count;
}

- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return  self.exercisePickerViewTitleBlock(row,self.datas[row]);
}

- (IBAction)cancle:(id)sender {
    [self dismiss];
}

- (IBAction)sure:(id)sender {
    self.exercisePickerViewResultBlock([self.picker selectedRowInComponent:0], self.datas[[self.picker selectedRowInComponent:0]]);
    [self dismiss];
}

- (void)awakeFromNib{
    [super awakeFromNib];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
